package com.example.export.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Component;

/**
 * @author dangwen1
 * @date 2021年12月03日 17:41
 * @description
 */
@Component
public class SpringBeanFactory implements BeanFactoryAware {
    private static BeanFactory ctx;
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        ctx = beanFactory;
    }

    public static <T> T getBean(Class<T> clazz) {
        return ctx.getBean(clazz);
    }

    public static Object getBean(String beanName){
        return ctx.getBean(beanName);
    }

    public static boolean containsBean(String beanName) {
        return ctx.containsBean(beanName);
    }
}
